<?php 
//商品分类的添加
	include_once("./com.php");
	error_reporting(E_ALL^E_NOTICE^E_WARNING);
	date_default_timezone_set("PRC");
	$set="select * from pc_fenlei";
	$res=mysql_query($set);
	while($list=mysql_fetch_assoc($res)){
	$sets[]=$list;
	};

	function arrav($sets,$fid=0){
		static $arr_arr=array();
		foreach($sets as $key=>$value){
			if($value['pc_fid']==$fid){
				$arr_arr[]=$value;
				arrav($sets,$value['pc_cid']);
			}
		}
		return $arr_arr;
	}
	$arr_arr=arrav($sets);
	if(isset($_GET['sub'])){
		$pc_name=$_GET['pc_name'];
		$pc_ifshow=$_GET['show'];
		$lcate=$_GET['lcate'];	
		$fid_level=explode("-",$lcate);
		$fid=$fid_level[0];
		$level=$fid_level[1]+1;
		$ins="insert into pc_fenlei(pc_name,pc_fid,pc_level,pc_ifshow)values('$pc_name','$fid','$level',$pc_ifshow)";
		mysql_query($ins);
		if(mysql_affected_rows()>0){
			echo "<script>
				alert('添加成功')
				location.href='product_cate.php'
				</script>";
		}else{
			echo "<script>
				alert('添加失败')
				location.href='product_cate_add.php'
				</script>";
		
		}
	}
 ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主体部分</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
</head>
<body leftmargin="8" topmargin='8'>
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' colspan="2"><span><img src='skin/images/frame/arr3.gif' style='margin-right:10px;'>添加商品分类</span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>
		<table style="margin-bottom:8px;margin-top:8px;margin-left:20px;">
			<form action="" method="">
			 <tr>
				<td width="100px;">上级分类:</td>
				<td>
					<select name="lcate">
					<option value="<?='0'.'-'.'0'?>">顶级分类</option>
				<?php foreach ($arr_arr as $value) { ?>
					<option value="<?= $value['pc_cid']."-".$value['pc_level']?>">
					<?= str_repeat("&nbsp;",($value['pc_level']-1)*6).$value['pc_name']?>
					</option>
				<?php } ?>
				   </select>
				</td>
			  </tr>
			   <tr>
				 <td>分类名称:</td>
				 <td><input type="text" name="pc_name" value=""></td>
			   </tr>
			   <tr>
				 <td>首页是否显示</td>
				 <td>
				 <input type="radio" name="show" value="1" checked>显示
				  <input type="radio" name="show" value="0"> 不显示</td>
			   </tr>
			   <tr>
				 <td colspan="2" align="center" height="40px">
				 	<input type="submit" name="sub" value=" 添加 " class="coolbt2"></td>
			   </tr>
			</form>
		</table>
	</td>
  </tr>
</table>
</body>
</html>